package cc.rengu.igas.momp.common.dao.impl;

import cc.rengu.igas.momp.common.dao.TBTradeAreaInfoMapper;
import cc.rengu.igas.momp.common.entity.TBTradeAreatInfo;
import cc.rengu.oltp.service.common.constant.AppConfigConstant;
import cc.rengu.oltp.service.common.constant.AppParamConstant;
import cc.rengu.oltp.utility.util.DbsUtil;
import cc.rengu.oltp.utility.util.XmlConfigUtil;
import cc.rengu.oltp.utility.util.XmlTreeUtil;
import cc.rengu.utility.cache.UnifiedCache;
import cc.rengu.utility.log.RgLog;
import cc.rengu.utility.log.RgLogger;

/**
 * 机构管理表数据库操作接口实现
 *
 * @author Jinan Liu
 * @version 1.0.0
 * @date 2020/6/22 19:56
 */

public class TBTradeAreaInfoMapperImpl implements TBTradeAreaInfoMapper {

    private RgLogger rglog = RgLog.getLogger(this.getClass().getName());
    String dbPoolName = XmlConfigUtil.getXmlConfigCacheKeyValue(AppParamConstant.DATABASE_CONF_NODE, AppConfigConstant.MCPS_POOL_NAME);

    /**
     * 查询商圈信息
     *
     * @param instId        多法人标识
     * @param tradeAreaCode 商圈编号
     * @return 商户基本信息
     * @throws Exception 异常
     */
    @Override
    public TBTradeAreatInfo selectTradeAreaInfoByTradeAreaCode(String instId, String tradeAreaCode) throws Exception {
        String dbPoolNameMCMP = XmlConfigUtil.getXmlConfigCacheKeyValue(AppParamConstant.DATABASE_CONF_NODE, AppConfigConstant.MCMP_POOL_NAME);
        XmlTreeUtil xmlTreeUtil = new XmlTreeUtil();
        String corporation = xmlTreeUtil.getXmlTreeStringValue(AppParamConstant.CORPORATION);
        if (null != corporation && !corporation.isEmpty()) {
            String dbPoolCashNode = corporation.trim() + AppParamConstant.DATABASE_CONF_NODE;
            dbPoolNameMCMP = XmlConfigUtil.getXmlConfigCacheKeyValue(dbPoolCashNode, AppConfigConstant.MCMP_POOL_NAME);
        }
        DbsUtil dbsUtil = new DbsUtil(dbPoolNameMCMP);
        String sqlStr = (String) UnifiedCache.get(AppParamConstant.SQL_MAPPER_CACHE, "mompSelectTradeAreaInfo");
        TBTradeAreatInfo TBTradeAreatInfo = new TBTradeAreatInfo();
        TBTradeAreatInfo.setInstId(instId);
        TBTradeAreatInfo.setTradeAreaCode(tradeAreaCode);
        //商圈状态 00-非正式,01-正式，02-停用，03-已注销
        TBTradeAreatInfo.setTradeAreaStatus("01");
        int iReturnCode = dbsUtil.dbsExecuteSql(sqlStr, TBTradeAreatInfo, TBTradeAreatInfo);
        if (0 != iReturnCode) {
            rglog.error("获取商圈基本信息失败,instId:<{}>,tradeAreaCode:<{}>,iReturnCode:<{}>", instId, TBTradeAreatInfo, iReturnCode);
            return null;
        }
        return TBTradeAreatInfo;
    }
}
